package queue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;

import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import com.google.protobuf.InvalidProtocolBufferException;

public class X {

	public static void main(String[] args) throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		CodedOutputStream cos = CodedOutputStream.newInstance(baos);
		cos.writeRawVarint32(1); //16K - 1
		cos.flush();
		
		ByteArrayInputStream is = new ByteArrayInputStream(baos.toByteArray());
		
		int n = -1;
		byte[] buf = new byte[5];
		is.read(buf, 0, 1);
		try {
			n = CodedInputStream.newInstance(buf, 0, 1).readRawVarint32();
		} catch (InvalidProtocolBufferException e0) {
			is.read(buf, 1, 1);	
			try {
				n = CodedInputStream.newInstance(buf, 0, 2).readRawVarint32();
			} catch (InvalidProtocolBufferException e1) {
				is.read(buf, 2, 1);
				try {
					n = CodedInputStream.newInstance(buf, 0, 3).readRawVarint32();
				} catch (InvalidProtocolBufferException e2) {
					is.read(buf, 3, 1);
					try {
						n = CodedInputStream.newInstance(buf, 0, 4).readRawVarint32();
					} catch (InvalidProtocolBufferException e3) {
						is.read(buf, 4, 1);
						n = CodedInputStream.newInstance(buf, 0, 5).readRawVarint32();
					}	
				}	
			}								
		}
		System.out.println(n);
	}
	
}
